package fantasyfootball.data.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 * Class: 605.441 
 * Group: Richard Koretke, Kay Jantharasorn, Israel Rivera.
 * 
 * @author Israel Rivera
 * 
 */
@Entity(name="NFLPlayer")
@NamedQueries({
	@NamedQuery(name="NFLPlayerSelectWithNFLTeam",query="SELECT DISTINCT p FROM NFLPlayer p INNER JOIN FETCH p.nflTeam")
})
public class NFLPlayer implements Serializable{

	private static final long serialVersionUID = 4348743208766830229L;
	
	private Integer playerID;
	private NFLTeam nflTeam;
	private String firstName;
	private String lastName;
	private String position;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="PlayerID", nullable=false, insertable=false, updatable=false)
	public Integer getPlayerID() {
		return playerID;
	}
	
	public void setPlayerID(Integer playerID) {
		this.playerID = playerID;
	}
	
	@JoinColumn(name="TeamName", nullable=false)
	@ManyToOne(fetch=FetchType.LAZY, optional=false)
	public NFLTeam getNflTeam() {
		return nflTeam;
	}

	public void setNflTeam(NFLTeam nflTeam) {
		this.nflTeam = nflTeam;
	}

	@Column(name="FirstName", nullable=true)
	public String getFirstName() {
		return firstName;
	}
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	@Column(name="LastName", nullable=false)
	public String getLastName() {
		return lastName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	@Column(name="Position", nullable=false)
	public String getPosition() {
		return position;
	}
	
	public void setPosition(String position) {
		this.position = position;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((playerID == null) ? 0 : playerID.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NFLPlayer other = (NFLPlayer) obj;
		if (playerID == null) {
			if (other.playerID != null)
				return false;
		} else if (!playerID.equals(other.playerID))
			return false;
		return true;
	}
}